/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2020年1月18日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.practice;

import java.util.Arrays;

/**
 * @Type A20200118_insertsort
 * @Desc
 * @author 52489
 * @date 2020年1月18日
 * @Version V1.0
 */
public class A20200118_insertsort {

    public static void main(String[] args) {
        int nums[] = { 3, 1, 2, 7, 5, 4 };
        insertSort(nums);
        System.out.println(Arrays.toString(nums));
    }

    /**
     * @param nums
     */
    private static void insertSort(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            int tmp = nums[i];
            int j = i;
            while (j >= 0) {
                if (j == 0) {
                    nums[j] = tmp;
                    j--;
                } else {
                    if (nums[j - 1] > tmp) {
                        nums[j] = nums[j - 1];
                        j--;
                    } else {
                        nums[j] = tmp;
                        break;
                    }
                }
            }
        }
    }

}
